<template>
  <a-modal
    :visible="show"
    width="80vw"
    min-height="60vh"
    title="项目变更历史"
    @ok="handleOk"
    @cancel="handleCancle"
    :maskClosable="false"
    :key="show"
  >
    <div class="header" style="padding: 10px 0px">
      <a-row type="flex" justify="space-between" align="middle">
        <a-col :xl="{ span: 14 }" :lg="{ span: 11 }">
          <a-button class="hte-btn add-btn" type="primary" @click="handleAdd">创建</a-button>
          <a-button class="hte-btn" plain @click="handleExport">导出</a-button>
          <a-button class="hte-btn" plain @click="handleReload">刷新</a-button>
          <a-button class="hte-btn" plain @click="handleDel" style="color: red">删除</a-button>
        </a-col>
        <a-col :xl="{ span: 9 }" :lg="{ span: 13 }" class="input-ground">
          <div style="display: flex">
            <a-input-group compact>
              <div style="display: flex">
                <a-select v-model="keywordType" @change="changeKeywordType">
                  <a-select-option value="1"> 变更单号</a-select-option>
                  <!-- <a-select-option value="2"> 项目编号 </a-select-option> -->
                </a-select>
                <a-input-search
                  v-if="keywordType == '1'"
                  v-model="searchForm.projectChangeNo"
                  @search="handleToSearch"
                  placeholder="请按照关键字进行搜索"
                />
                <a-input-search
                  v-if="keywordType == '2'"
                  v-model="searchForm.projectNo"
                  @search="handleToSearch"
                  placeholder="请按照关键字进行搜索"
                />
              </div>
            </a-input-group>
            <a-button class="hte-btn del-btn" @click="showSearchForm = true">高级搜索</a-button>
          </div>
        </a-col>
      </a-row>
      <a-modal
        :visible="showSearchForm"
        width="70vw"
        :bodyStyle="{ padding: '10px' }"
        title="高级查询"
        @ok="handleToSearch"
        @cancel="showSearchForm = false"
      >
        <a-form-model
          ref="ruleForm"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          @keyup.enter.native="handleToSearch"
        >
          <a-row :gutter="24">
            <a-col :span="8">
              <a-form-model-item label="审批状态">
                <a-select v-model="searchForm.withInStatus" style="width: 100%" allowClear>
                  <a-select-option value=""> 全部 </a-select-option>
                  <a-select-option v-for="(code, index) in codes['工程项目变更状态']" :key="index" :value="code.code">
                    {{ code.name }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="变更单号">
                <a-input allow-clear v-model="searchForm.projectChangeNo" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="变更名称">
                <a-input allow-clear v-model="searchForm.projectChangeName" />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col :span="8">
              <a-form-model-item label="主要负责人">
                <a-input allow-clear v-model="searchForm.dutyUserName" />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-modal>
    </div>
    <div class="content-list">
      <a-table
        :columns="columns"
        :data-source="records"
        rowKey="id"
        bordered
        :pagination="false"
        :customRow="customRow"
        :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :loading="loading"
      >
        <template slot="statusRender" slot-scope="text, record">
          <a-tooltip>
            <template #title>状态不对?点我更新</template>
            <a-icon type="sync" @click="updateStatus(record.id)" />
          </a-tooltip>
          {{ getCodeNames(text, '工程项目变更状态') }}
        </template>
      </a-table>
      <a-pagination
        show-size-changer
        :default-current="1"
        :total="searchForm.total"
        @change="pageChange"
        @showSizeChange="onShowSizeChange"
        :show-total="(total) => `共 ${total} 条记录`"
      />
    </div>
  </a-modal>
</template>
<script>
import { ProjectChangeListMixin } from '@/views/projectChange/ProjectChangeListMixin'
import { postAction } from '@/api/manage'
export default {
  mixins: [ProjectChangeListMixin],
  data() {
    return {
      show: false,
      columns: [
        {
          title: '序号',
          dataIndex: 'sortIndex',
          width: '80px',
          align: 'center',
          customRender: (text, record, index) => {
            return index + 1
          },
        },
        {
          title: '审批状态',
          dataIndex: 'status',
          scopedSlots: { customRender: 'statusRender' },
          width: '100px',
          align: 'center',
          // customCell: () => {
          //   return this.customCellRender(130)
          // },
          // customRender: (text, record) => {
          //   return this.tooltipRender(this.getCodeNames(text, '工程项目变更状态'), record)
          // },
        },
        {
          title: '变更单号',
          dataIndex: 'projectChangeNo',
          align: 'center',
          width: '130px',
          customCell: () => {
            return this.customCellRender(130)
          },
          customRender: (text, record) => {
            return this.tooltipActiveRender(text, record, 'toDetail')
          },
        },
        {
          title: '变更名称',
          dataIndex: 'projectChangeName',
          align: 'left',
          width: '230px',
          ellipsis: true,
          customCell: () => {
            return this.customCellRender(230)
          },
          customRender: (text, record) => {
            return this.tooltipRender(text, record)
          },
        },
        {
          title: '预算变更内容',
          dataIndex: 'budgetChangeContent',
          align: 'center',
          width: '230px',
          customCell: () => {
            return this.customCellRender(230)
          },
          customRender: (text, record) => {
            return this.tooltipRender(this.getCodeNames(text, '工程项目项目预算变更类型'), record)
          },
        },
        {
          title: '其他变更内容',
          dataIndex: 'changeContent',
          align: 'center',
          width: '230px',
          customCell: () => {
            return this.customCellRender(230)
          },
          customRender: (text, record) => {
            let text1 = this.getCodeNames(text, '工程项目其他变更内容')
            let text2 = this.getCodeNames(record.contractChangeContent, '工程项目变更合同涉及内容')

            if (text1 && text2) {
              return this.tooltipRender(text1 + ',' + text2, record)
            } else if (text1) {
              return this.tooltipRender(text1, record)
            } else if (text2) {
              return this.tooltipRender(text2, record)
            }
          },
        },
        {
          title: '申请人',
          dataIndex: 'createUserName',
          align: 'center',
          width: '80px',
        },
        {
          title: '申请时间',
          dataIndex: 'createTime',
          align: 'center',
          width: '100px',
          customCell: () => {
            return this.customCellRender(100)
          },
          customRender: (text, record) => {
            return this.timeRender(text, record, 'yyyy-MM-dd')
          },
        },
      ],
      urls:{
        updateStatus: '/projectChange/updateStatus',
      }
    }
  },
  async mounted() {},
  methods: {
    openInit(projectBuildId, projectNo, projectName, projectManager) {
      this.records = []
      this.$set(this.searchForm, 'pageNo', 1)
      this.$set(this.searchForm, 'pageSize', 10)
      this.$set(this.searchForm, 'projectBuildId', projectBuildId)
      this.$set(this.searchForm, 'projectNo', projectNo)
      this.$set(this.searchForm, 'projectName', projectName)
      this.$set(this.searchForm, 'projectManager', projectManager)
      this.fetchList()
      this.show = true
    },
    handleOk() {
      this.handleCancle()
    },
    handleCancle() {
      this.show = false
    },
    handleAdd() {
      let urlJump = this.$router.resolve({
        path: '/projectChange/changeRecord?addByProject=true&projectBuildId=' + this.searchForm.projectBuildId,
      })
      window.open(urlJump.href, '_blank')
    },
    updateStatus(id) {
      postAction(this.urls.updateStatus + '?changeId=' + id).then((res) => {
        if (res.success) {
          this.$messageWorkReport.success('更新成功')
          this.handleToSearch()
        } else {
          this.$messageWorkReport.error('更新失败')
        }
      })
    },
  },
  watch: {},
}
</script>

<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
.page-main {
  .container {
    .content {
      margin-top: 20px;
      section {
        margin-bottom: 18px;
        .section-table {
          .add-btn {
            margin-left: 0;
            margin-bottom: 10px;
          }
          /deep/ .a-upload__input {
            display: none !important;
          }
        }
      }
    }
  }
  .tips-box {
    margin-top: 32px;
    .add-btn {
      width: 180px;
      height: 40px;
      line-height: 40px;
      background-color: #4095e4;
      border-radius: 2px;
    }
  }
}
/deep/ .el-upload__input {
  display: none !important;
}
</style>
